return ($n > 0);
}
- const UNDELETE_NOTHINGRESTORED = 0; // No revisions could be restored
- const UNDELETE_NOTAVAIL = -1; // Not all requested revisions are available
- const UNDELETE_UNKNOWNERR = -2; // Unknown error
/**
* Restore the given (or all) text and file revisions for the page.
* Once restored, the items will be removed from the archive tables.
* @param string $comment
* @param array $fileVersions
*
- * @return array(number of revisions restored, number of file versions restored, log reason) on success or UNDELETE_* on failure
+ * @return array(number of file revisions restored, number of image revisions restored, log message)
+ * on success, false on failure
*/
function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
// If both the set of text revisions and file revisions are empty,
if( $restoreText ) {
$textRestored = $this->undeleteRevisions( $timestamps );
- if($textRestored < 0) // It must be one of UNDELETE_*
- return $textRestored;
+ if($textRestored === false) // It must be one of UNDELETE_*
+ return false;
} else {
$textRestored = 0;
}
$wgContLang->formatNum( $filesRestored ) );
} else {
wfDebug( "Undelete: nothing undeleted...\n" );
- return self::UNDELETE_NOTHINGRESTORED;
+ return false;
}
if( trim( $comment ) != '' )
* @param string $comment
* @param array $fileVersions
*
- * @return int number of revisions restored on success or UNDELETE_* on failure
+ * @return mixed number of revisions restored or false on failure
*/
private function undeleteRevisions( $timestamps ) {
- if ( wfReadOnly() ) return 0;
+ if ( wfReadOnly() )
+ return false;
$restoreAll = empty( $timestamps );
);
if( $dbw->numRows( $result ) < count( $timestamps ) ) {
wfDebug( __METHOD__.": couldn't find all requested rows\n" );
- return self::UNDELETE_NOTAVAIL;
+ return false;
}
$revision = null;
'unblock-notarget' => array('code' => 'notarget', 'info' => "Either the id or the user parameter must be set"),
'unblock-idanduser' => array('code' => 'idanduser', 'info' => "The id and user parameters can\'t be used together"),
'cantunblock' => array('code' => 'permissiondenied', 'info' => "You don't have permission to unblock users"),
+ 'cannotundelete' => array('code' => 'cantundelete', 'info' => "Couldn't undelete: the requested revisions may not exist, or may have been undeleted already"),
+ 'permdenied-undelete' => array('code' => 'permissiondenied', 'info' => "You don't have permission to restore deleted revisions"),
);
/**
$titleObj = NULL;
if(!isset($params['title']))
- $this->dieUsage('The title parameter must be set', 'notitle');
+ $this->dieUsageMsg(array('missingparam', 'title'));
if(!isset($params['token']))
- $this->dieUsage('The token parameter must be set', 'notoken');
+ $this->dieUsageMsg(array('missingparam', 'token'));
if(!$wgUser->isAllowed('undelete'))
- $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied');
+ $this->dieUsageMsg(array('permdenied-undelete'));
if($wgUser->isBlocked())
- $this->dieUsage('You have been blocked from editing', 'blocked');
+ $this->dieUsageMsg(array('blockedtext'));
if(wfReadOnly())
- $this->dieUsage('The wiki is in read-only mode', 'readonly');
+ $this->dieUsageMsg(array('readonlytext'));
if(!$wgUser->matchEditToken($params['token']))
- $this->dieUsage('Invalid token', 'badtoken');
+ $this->dieUsageMsg(array('sessionfailure'));
$titleObj = Title::newFromText($params['title']);
if(!$titleObj)
- $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');
+ $this->dieUsageMsg(array('invalidtitle', $params['title']));
// Convert timestamps
if(!is_array($params['timestamps']))
$dbw->begin();
$retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);
if(!is_array($retval))
- switch($retval)
- {
- case PageArchive::UNDELETE_NOTHINGRESTORED:
- $this->dieUsage('No revisions could be restored', 'norevs');
- case PageArchive::UNDELETE_NOTAVAIL:
- $this->dieUsage('Not all requested revisions could be found', 'revsnotfound');
- case PageArchive::UNDELETE_UNKNOWNERR:
- $this->dieUsage('Undeletion failed with unknown error', 'unknownerror');
- }
+ $this->dieUsageMsg(array('cannotundelete'));
+
$dbw->commit();
-
$info['title'] = $titleObj->getPrefixedText();
$info['revisions'] = $retval[0];
$info['fileversions'] = $retval[1];